package com.fit.dao.user;

import java.util.List;

import org.apache.tapestry5.ioc.annotations.Inject;
import org.hibernate.Session;

import com.fit.entities.User;

public class UserDAOImpl implements UserDAO{

	@Inject
	private Session session;
	
	public boolean save(User newUser) {
		if (newUser != null) {
			session.save(newUser);
			return true;
		}
		return false;
		
	}

	public boolean delete(User user) {
		if (user != null) {
			session.delete(user);
			return true;
		}
		return false;
	}

	public boolean update(User user) {
		if (user != null) {
			session.update(user);
			return true;
		}
		return false;
	}

	public List<User> findAll() {
		return session.createCriteria(User.class).list();
		
	}

	public User findByID(Long id) {
		if (id != null) {
			return (User) session.get(User.class, id);
		}
		return null;
	}

	public boolean deleteByID(Long id) {
		User u = findByID(id);
		if (u != null) {
			delete(u);
			return true;
		}
		return false;
	}

}
